// const {
// 	default: data
// } = require("custom-tab-bar/data");

const GET = 'GET';
const POST = 'POST';
// const baseUrl = 'http://111.203.231.105:801';
const app = getApp()
const baseUrl = app.globalData.baseApiUrl ;

function request(method, url, data, header = { 'content-type': 'application/json' }) {
  return new Promise((resolve, reject) => {

    // let header = {
    //   'content-type': 'application/json'
    // };
    wx.request({
      url: baseUrl + url,
      method,
      header,
      // data: method === POST ? JSON.stringify(data) : data,
      data,
      success: (res) => {
        // console.log(data);
        if (res.statusCode === 200) {
          resolve(res);
        } else {
          reject('运行时错误,请稍后再试');
        }
      },
      fail: (err) => {
        reject(err);
      }
    })
  }).catch((e) => {});
}
const Api = {
  // 状态 0:未付款 1:未发货 2:待收货 5:已完成  7:订单关闭
  // 来源 1.小程序商城 2.现场购 3.预售自提
  // getActivity: (data) => request(GET, 'media/activity/detail', data),
  // getsiwper: () => request(GET, 'media/activity/newest'),
  login: (data) => request(POST, `/api/login/wxLogin?code=${data.code}`), //登录
  headPortrait: (data) => request(POST, `/api/login/headPortrait?headPortrait=${data.headPortrait}&headPortrait=${data.memberNumber}`), //登录
  getUsePhone: (data) => request(POST, `/api/login/getUsePhone?code=${data.code}&memberNumber=${data.memberNumber}&openid=${data.memberNumber}&openId=${data.memberNumber}`), //获取手机号
  goodsList: (data) => request(POST, `/api/goods/goodsList?page=${data.page}&size=${data.size}&vin=${data.vin}`), //商品列表
  goodsDetails: (data) => request(POST, `/api/goods/goodsDetails?productNumber=${data.productNumber}&vin=${data.vin}&shippingSpace=${data.shippingSpace}`), //商品详情
  orderCreate: (data) => request(POST, `/api/order/create?
	name=${data.name}&
	num=${data.num}&
	address=${data.address}&
	phone=${data.phone}&
	productTitle=${data.productTitle}&
	zongPrice=${data.zongPrice}&
	source=${data.source}&
	productSize=${data.productSize}&
	userId=${data.userId}&
	vin=${data.vin}&
	goodsId=${data.goodsId}&
	conId=${data.conId}&
  goodsInfo=${data.goodsInfo}
  productNumber=${data.discountPrice}
  
	`), //创建订单

  getGoodsSku: (data) => request(POST, `/api/goods/getGoodsSku?goodsId=${data.id}`), //获取商品sku
  getAllVoucher: (data) => request(POST, `/api/voucher/getAllVoucher`, data, { 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8' }), //获取商品sku
  addUserVoucher: (data) => request(POST, `/api/voucher/addUserVoucher`, data, { 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8' }),
  getListUserVoucher: (data) => request(POST, `/api/voucher/getListUserVoucher`, data, { 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8' }), //获取商品sku

  getGoodsInventory: (data) => request(POST, `/api/goods/getGoodsInventory?
	productId=${data.productId}&
	productSize=${data.productSize}`), //根据sku获取库存

  addShoppingCart: (data) => request(POST, `/api/shopping/addShoppingCart?
	goodsId=${data.goodsId}&
	price=${data.price}&
	productSize=${data.productSize}&
	sizeName=${data.sizeName}&
	useId=${data.useId}&
	yuanPrice=${data.yuanPrice}&
	goodsNum=${data.goodsNum}&
	vin=${data.vin}&
	shippingSpace=${data.shippingSpace}&
  productNumber=${data.productNumber}
  productNumber=${data.discountPrice}
	`), //添加购物车

  shoppingCartList: (data) => request(POST, `/api/shopping/shoppingCartList?
	memberNumber=${data.memberNumber}&
	page=${data.page}&
	size=${data.size}&
	source=${data.source}&
	vin=${data.vin}
	`), //购物车列表
  updateCart: (data) => request(POST, `/api/shopping/updateCart?
	param=${data.param}
	`), //购物车钱数加减
  orderDetails: (data) => request(POST, `/api/order/orderDetails?
	orderCode=${data.orderCode}
	
	`), //订单详情查询
  giftCardInfo: (data) => request(POST, `/api/giftCard/giftCardInfo?
	exchangeOrderCode=${data.exchangeOrderCode}
	
	`), //订单详情查询

	// status=${data.status}&
  orderList: (data) => request(POST, `/api/order/orderList?
	userId=${data.userId}&
	page=${data.page}&
	size=${data.size}&
	source=${data.source}
  `), //订单列表
  refundList:(data)=>request(POST, `/api/refund/refundList?
	memberNumber=${data.memberNumber}&
	pagNum=${data.pagNum}&
	pagSize=${data.pagSize}
  `), //售后列表
  // refund:(data)=>request(POST, `/api/refund/refund?
	// memberNumber=${data.memberNumber}&
	// orderCode=${data.orderCode}&
	// amount=${data.amount}&
	// contacts=${data.contacts}&
	// phone=${data.phone}&
	// cause=${data.cause}&
	// goodsInfo=${data.goodsInfo}
  // `), //申请退款
  refund:(data)=>request(POST, `/api/refund/refund`, data, { 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8' }), //申请退款
  refundCalculate:(memberNumber, data)=>request(POST, `/api/refund/refundCalculate`, { param: JSON.stringify(data), memberNumber }, { 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8' }), //退款金额计算
  // refundCalculate:(data)=>request(POST, `/api/refund/refundCalculate`, { param: data }), //退款金额计算
  deleteShoppingCartList: (data) => request(POST, `/api/shopping/deleteShoppingCartList?
	memberNumber=${data.memberNumber}&
	source=${data.source}&
	cartId=${data.cartId}
	`), //单删
  deleteShoppingCartListquanbu: (data) => request(POST, `/api/shopping/deleteShoppingCartList?
	memberNumber=${data.memberNumber}&
	source=${data.source}
	`), //全删
  verifyDeliveryCode: (data) => request(POST, `/api/giftCard/verifyDeliveryCode?deliveryCode=${data.deliveryCode}`),
  giftCardList:(data)=>request(POST, `/api/giftCard/giftCardList?
	memberNumber=${data.memberNumber}&
	pagNum=${data.pagNum}&
	pagSize=${data.pagSize}
  `), //售后列表
  getKaptchaImage: () => request(POST, `/api/kaptcha/getKaptchaImage`),
  verify: (data) => request(POST, `/api/kaptcha/verify?code=${data.code}&uuid=${data.uuid}`),
  addShippingAddress: (data) => request(POST, `/api/giftCard/addShippingAddress?memberNumber=${data.memberNumber}&
	deliveryCode=${data.deliveryCode}&
	phone=${data.phone}&
	address=${data.address}&
	consignee=${data.consignee}
  `),
  yuzhifu: (data) => request(POST, `/api/pay/yuzhifu?
	openid=${data.openid}&
	number=${data.number}&
	pay=${data.pay}&
	jine=${data.pay}&
	staff_no=${data.staff_no}&
	NAME=微信用户
  `), //支付

};
module.exports = {
  Api
}
